import Router from 'vue-router';
const component = (layout) => () => import(/* webpackChunkName: "[request]" */`../layout/${layout}`);

const routes = [{
  path: '*',
  redirect: '/main',
}, {
  path: '/main',
  name: 'main',
  component: component('page1')
}, {
  path: '/sub',
  name: 'sub',
  component: component('page2')
}];

export default () => {
  return new Router({
    mode: 'history',
    routes,
    fallback: true,
    linkActiveClass: 'link-active',
    linkExactActiveClass: 'exact-link-active',
    scrollBehavior (to, from, savedPosition) {
      // toto
      if (savedPosition) {
        return savedPosition;
      } else {
        return { x: 0, y: 0 };
      }
    }
  })
}
